<?php
class Controller_Ads extends Controller_Client_Layout
{
    /**
     * Get all banners
     *
     * @access public
     * @param <type> $position
     * @return <type>
     */
    public function action_get_banner($position)
    {
        switch ($position)
        {
            case 'top':
                $width = '575';
            case 'bottom':
                break;
            case 'left':
            case 'right':
                $width = '220';
                break;
            default :
                return;
        }
        $this->auto_render = FALSE;

        $banners = Doctrine_Query::create()
                ->from('Ads a')
                ->where('a.type = ?', 'banner')
                ->addWhere('a.position = ?', $position)
                ->orderBy('a.metadata ASC')
                ->execute();

        if(count($banners) > 0)
        {
            $view = View::factory('client/show_banner', array(
                'banners' => $banners,
                'width'   => $width
            ));
            $this->response->body($view->render());
        }
    }

    /**
     * Get all partner
     *
     * @access public
     */
    public function action_get_partner()
    {
        $this->auto_render = FALSE;

        $partners = Doctrine_Query::create()
                ->from('Ads a')
                ->where('a.type = ?', 'partner')
                ->orderBy('a.metadata ASC')
                ->execute();

        if(count($partners) > 0)
        {
            $view = View::factory('client/show_partner', array(
                'partners' => $partners
            ));
            $this->response->body($view->render());
        }
    }
    
    public function action_get_exchange_service()
    {
        $this->auto_render = false;
        
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, "http://www.sacombank-sbj.com/service/tygiatrongnuoc.ashx"); 

        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 
        curl_close($ch);

        $this->response->body(View::client('show_exchange')->set(array(
            'service' => $output
        )));
    }
}